package com.example.myactspringboot;

import com.example.myactspringboot.bean.SysMenu;
import com.example.myactspringboot.bean.SysRole;
import com.example.myactspringboot.bean.SysRoleMenu;
import com.example.myactspringboot.bean.SysUser;
import com.example.myactspringboot.dao.SysMenuMapper;
import com.example.myactspringboot.dao.SysRoleMapper;
import com.example.myactspringboot.dao.SysUserMapper;
import com.example.myactspringboot.dao.UserCHMapper;
import com.example.myactspringboot.util.Time22KeyGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.awt.print.Pageable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Create 2023-09-23 14:46
 * @Description
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyActSpringBootApplication.class)
public class 权限菜单 {
    @Autowired
    SysMenuMapper menuMapper;
    @Autowired
    SysRoleMapper roleMapper;



    @Test
    public void hah(){
        SysMenu sysMenu = new SysMenu();
        sysMenu.setCreateTime(new Date());
        sysMenu.setCreateUser("admin");
        sysMenu.setId(new Time22KeyGenerator().getNext());
        sysMenu.setParentId("0");
        sysMenu.setFlag("1");
        sysMenu.setIsShow("1");
        int i = menuMapper.saveMenu(sysMenu);
        System.out.println(i);
    }

    @Test
  public   void saveRole(){
        for (int j=60;j>0;j--) {
            SysRole sysRole = new SysRole();
            sysRole.setId(new Time22KeyGenerator().getNext());
            sysRole.setCreateBy("admin");
            sysRole.setCreateDate(new Date());
            sysRole.setName("管理员");
            sysRole.setFlag("1");
            sysRole.setSort(1);
            sysRole.setType("1");
            int i = roleMapper.saveSysRole(sysRole);
            System.out.println(i);
        }
    }

    @Test
    public void saveRoleMenu(){
        ArrayList<SysRoleMenu> sysRoleMenus = new ArrayList<>();
        SysRole admin = roleMapper.getRoleById("2023092315111277100198");
        for (SysMenu sysMenu : menuMapper.getMenuList()) {
            SysRoleMenu sysRoleMenu = new SysRoleMenu();
            sysRoleMenu.setMenuId(sysMenu.getId());
            sysRoleMenu.setRoleId(admin.getId());
            sysRoleMenus.add(sysRoleMenu);
        }
        int i = roleMapper.saveRoleMenu(sysRoleMenus);
        System.out.println(i);
    }
    @Autowired
    SysUserMapper userMapper;
    @Test
    public void getUserMes(){
        SysUser admin = userMapper.getUserByName("admin");
        List<SysMenu> menuListByUserId = menuMapper.getMenuListByUserId(admin.getId());
        for (SysMenu sysMenu : menuListByUserId) {
            System.out.println(sysMenu);
        }
    }
    @Autowired
    UserCHMapper userCHMapper;
    @Test
    public void chTest(){
        PageHelper.startPage(1,4);
        List<Map<String, Object>> all = userCHMapper.getAll();
        PageInfo pageInfo = new PageInfo(all,5);
        System.out.println(pageInfo);
    }
}
